package com.soteind.system.notifications;

import com.soteind.system.session.SoteindConfig;
import com.soteind.system.session.SoteindSession;
import com.soteind.view.ViewUtils;
import com.soteind.system.notifications.Notifier;
import com.soteind.system.session.core.CoreConfig;
import java.util.Map;
import javax.persistence.EntityManagerFactory;

/**
 *
 * @author Daniel Moreno
 */
abstract public class SoteindNotifier extends Notifier {

    public SoteindNotifier(EmailSender emailSender, EntityManagerFactory emf) {
		super(emailSender, emf);
		// TODO Auto-generated constructor stub
	}
    
    public SoteindNotifier(String notificationNameKey, EntityManagerFactory emf,
            SoteindSession soteindSession) {
        super(null, notificationNameKey, emf);
        this.soteindSession = soteindSession;
    }
    
    private SoteindSession soteindSession;

    @Override
    protected String getCurrentFullUserName(String language) {
        StringBuilder str = new StringBuilder();
        if (soteindSession.isAlreadyLogged()) {
            return soteindSession.getCurrentUser().getFullName();
        }
        return "";
    }

    @Override
    public String getCompanyNAME() {
        return CoreConfig.getFileProperty("companyname");
    }

    @Override
    public String getComapanyURL() {
        return CoreConfig.getFileProperty("companyurl");
    }

    @Override
    public String getFromName(String string) {
        return getComapanyURL();
    }

    @Override
    public String getFromEmail() {
        return SoteindConfig.getFileProperty("mailfrom");
    }
    //
    // Utilidades

    public String buildAbsoluteUrl(String relativeToFacesUrl, Map<String, String> queryStrings) {
        ViewUtils viewUtils = new ViewUtils(getEmf());

        StringBuilder str = new StringBuilder(SoteindConfig.getFileProperty(SoteindConfig.PARAM_NAME_SERVERURL));
        str.append(viewUtils.buildViewUrl(relativeToFacesUrl, queryStrings));
        return str.toString();
    }
}
